package com.akhan.jplearn.util;

import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.resource.ClassPathResource;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;

import java.io.InputStream;
import java.util.List;

/**
 * 回答失败提示工具类
 *
 * @author YuKang
 * @date 2021/6/25 0:42
 */
public class FailMsgUtil {
    private static List<String> msgs = Lists.newArrayList();

    static {
        ClassPathResource resource = new ClassPathResource("FailMsg");
        InputStream is = resource.getStream();
        IoUtil.readLines(is, "utf-8", Lists.newArrayList()).forEach(n -> {
            msgs.add(n);
        });
    }

    public static String randomMsg(String answer) {
        String msg = msgs.get(RandomUtil.randomInt(0, msgs.size() - 1));

        return StrUtil.format(msg, answer);
    }
}
